package com.blustreaksw.cyclecoach.util;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;

/***********************************************************************
 * Helper class to simply creation of ListPicker popup dialog.
 * 
 * @author Tomas Rivera
 *
 ***********************************************************************/
public class ListPickerDialogFragment extends DialogFragment {
	
	private int mArrayId;
	private String mDialogTitle;
	private DialogInterface.OnClickListener mListener;
	private Context mContext;
	
	public ListPickerDialogFragment() {}
	
	/********************************************************************************
	 * Configures dialog fragment that was created with default constructor.
	 * 
	 * @param	itemClickListener
	 * 		OnClickListener that handles when a user selects an item in the list.
	 * @param	title
	 * 		String to be displayed in the dialog title bar.
	 * @param	arrayId
	 * 		int string-array to use in the dialog list.
	 * @param	context
	 * 		Application context that the caller belongs to.
	 * @return	ListPickerDialogFragment object
	 ********************************************************************************/
	public ListPickerDialogFragment configureListDialog(
			DialogInterface.OnClickListener itemClickListener, String title, 
			int arrayId, Context context) {
		mArrayId = arrayId;
		mDialogTitle = title;
		mListener = itemClickListener;
		mContext = context;
		return this;
	}
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
		builder.setTitle(mDialogTitle).setItems(mArrayId, mListener);
		return builder.create();
	}
}
